package com.korubo.web.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.korubo.kit.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.korubo.web.model.Carousel;
import com.korubo.web.mapper.CarouselMapper;
import com.korubo.web.service.CarouselService;

@Service
public class CarouselServiceImpl extends ServiceImpl<CarouselMapper, Carousel> implements CarouselService {

    @Resource
    private CarouselMapper carouselMapper;

    @Override
    public R list(Carousel entity) {
        QueryWrapper<Carousel> queryWrapper = new QueryWrapper<>();
        if (null != entity) {
            if (StrUtil.isNotBlank(entity.getName())) {
                queryWrapper.like("name", entity.getName());
            }
            if (StrUtil.isNotBlank(entity.getStatus())) {
                queryWrapper.eq("status", entity.getStatus());
            }
        }
        Page<Carousel> carouselPage = carouselMapper.selectPage(new Page<>(entity.getPageNum(), entity.getPageSize()), queryWrapper);
        return R.ok(carouselPage);
    }

    @Override
    public R findByStatus() {
        QueryWrapper<Carousel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", 1);
        List<Carousel> carousels = carouselMapper.selectList(queryWrapper);
        return R.ok(carousels);
    }
}
